xquery version "1.0";

import module namespace layout="http://www.example.com/layout" at "xmldb:exist:///db/projdb/modules/layout.xqm";
import module namespace request="http://exist-db.org/xquery/request";

declare option exist:serialize "doctype-public=-//W3C//DTD&#160;XHTML&#160;1.1//EN
                                doctype-system=http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd";

declare variable $summ {document('/db/projdb/onderbrekerstotalen.xml')/onderbrekerstotalen}; 
declare variable $burgemeesters{document('/db/projdb/lijst_burgemeesters_2007.xml')/burgemeesters/tupel};
declare variable $names {document('/db/projdb/lijst_van_sprekers_ge2009.xml')/speakers/speaker};
declare variable $aantal {count($names/name)};
declare variable $aantalb { count(for $j in $names/name let $b := $burgemeesters[./burgemeester = $j] where not(empty($b)) return $j)};
declare variable $test {for $j in $names/name let $b := $burgemeesters[./burgemeester = $j] where not(empty($b)) return $j};
declare variable $aantalnburg { xs:integer($aantal) - xs:integer($aantalb)};
declare variable $onderbrekingsBurg{ round-half-to-even(sum($summ/entry[./burgemeester = 'Y']/aantal) div $aantalb,2)};
declare variable $onderbrekingsNBurg{round-half-to-even(sum($summ/entry[./burgemeester= 'N']/aantal) div $aantalnburg,2)};
declare variable $onderbrekingsBurgGraf {<img src="http://chart.apis.google.com/chart?chxt=y&amp;chbh=a&amp;chs=700x250&amp;cht=bvg&amp;chco=000080|800000&amp;chd=t:{$onderbrekingsBurg},{$onderbrekingsNBurg}&amp;chbh=a,200,200&amp;chl=Burgemeesters|Niet burgemeesters" />};

declare variable $aantalbo {count($summ/entry[./burgemeester = 'Y'])};
declare variable $aantalnbo {count($summ/entry[./burgemeester = 'N'])};
declare variable $onderbrekingsTovEigenBurg{round-half-to-even(100 *$aantalbo div $aantalb,2)};
declare variable $onderbrekingsTovEigennBurg{round-half-to-even(100 *$aantalnbo div $aantalnburg,2)};
declare variable $onderbrekingsTovEigenGraf {<img src="http://chart.apis.google.com/chart?chxt=y&amp;chbh=a&amp;chs=700x250&amp;cht=bvg&amp;chco=000080|800000&amp;chd=t:{$onderbrekingsTovEigenBurg},{$onderbrekingsTovEigennBurg}&amp;chbh=a,200,200&amp;chl=Burgemeesters|Niet burgemeesters" />};

declare function local:getSingleLabelsBurgemeesters( $amount ) as element()
{
    let $singleLabels := subsequence( document('/db/projdb/clusterdataMostPopular.xml')/result/singleLabels/burgemeesters/label, 1, $amount )
    
    return element ol {
        for $label in $singleLabels
            return element li {
                data($label/name)," (",data($label/occurences),")"
            }
    }
};

declare function local:getSingleLabelsNietBurgemeesters( $amount ) as element()
{
    let $singleLabels := subsequence( document('/db/projdb/clusterdataMostPopular.xml')/result/singleLabels/nietBurgemeesters/label, 1, $amount )
    
    return element ol {
        for $label in $singleLabels
            return element li {
                data($label/name)," (",data($label/occurences),")"
            }
    }
};

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="nl">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>Activiteit in de plenaire vergaderingen</title>
        <link rel="stylesheet" style="text/css" href="style/core_layout.css"/>
		<script type="text/javascript" src="js/jquery.js"><!-- --></script>
        <script type="text/javascript" src="https://www.google.com/jsapi"><!-- --></script>
        <script type="text/javascript" src="js/activity.js"><!-- --></script>
        <script type="text/javascript" src="js/myScripts.js"><!-- --></script>
        <script type="text/javascript">
            //<![CDATA[
            google.load("visualization", "1", {packages:["corechart"]});
            google.setOnLoadCallback(function() {
                initShowHideButtons();

                activity_setUpdateFunction(function(xml) {
                      activity_loadMayorRankingChart(xml, "mayorRankingChartContainer", 700, 400);
                      activity_loadMayorQuartilePieChart(xml, "mayorQuartileChartContainerMayor", 'TRUE', true);
                      activity_loadMayorQuartilePieChart(xml, "mayorQuartileChartContainerNoneMayor", 'FALSE', true);
                      
                      activity_loadQuartileMayorPieChart(xml, "mayorRankingPieChartFirstPartContainer", 'firstPart', 'Kwartiel 1 (top)');
                      activity_loadQuartileMayorPieChart(xml, "mayorRankingPieChartSecondPartContainer", 'secondPart', 'Kwartiel 2');
                      activity_loadQuartileMayorPieChart(xml, "mayorRankingPieChartThirdPartContainer", 'thirdPart', 'Kwartiel 3');
                      activity_loadQuartileMayorPieChart(xml, "mayorRankingPieChartFourthPartContainer", 'fourthPart', 'Kwartiel 4');


                });

                activity_run();
            });
            //]]>
        </script>
        
        
    </head>
    <body>	
          <div class="containerBox">
          {layout:topMenu()}
  
        <div class="box" id="titleBox">
            <div class="margin">
                <h1>Burgemeesters vs Niet-burgemeesters</h1>
            </div>
        </div>

        <div class="box" id="mayorActivityChartBox">
            <div class="margin">
                <h2 class="boxTitle">Activeitsranking</h2>
                <div class="boxContent">
                     <div id="mayorRankingChartContainer">
                        <!-- Auto generated -->
                    </div>
                </div>
            </div>
        </div>

        <div class="box" id="ppartyRankingPieChartBox">
            <div class="margin">
                <h2 class="boxTitle">Kwartielen</h2>
                <div class="boxContent columnContent">
                    <div class="columnspace twoColumns">
                        <div class="column" id="mayorRankingPieChartFirstPartContainer" style="height:250px;"><!-- Auto generated --></div>
                        <div class="column" id="mayorRankingPieChartSecondPartContainer" style="height:250px;"><!-- Auto generated --></div>
                        <br class="clearer" />
                    </div>
                    <div class="columnspace twoColumns">
                        <div class="column" id="mayorRankingPieChartThirdPartContainer" style="height:250px;"><!-- Auto generated --></div>
                        <div class="column" id="mayorRankingPieChartFourthPartContainer" style="height:250px;"><!-- Auto generated --></div>
                        <br class="clearer" />
                    </div>
                </div>
            </div>
        </div>

        <div class="box" id="mayorQuartileChartBox">
            <div class="margin">
                <h2 class="boxTitle">Kwartielen per Burgemeester/Niet-burgemeester</h2>
                <div class="boxContent columnContent">
                    <div class="columnspace twoColumns">
                        <div class="column" id="mayorQuartileChartContainerNoneMayor" style="height:250px;"><!-- Auto generated --></div>
                        <div class="column" id="mayorQuartileChartContainerMayor" style="height:250px;"><!-- Auto generated --></div>

                        <br class="clearer" />
                    </div>
                </div>
            </div>
        </div>

        <div class="box" id="mostPopularSingleLabelSubjectsMayors">
            <div class="margin">
                <h2 class="boxTitle">Meest populaire onderwerpen <span class="button"></span></h2>
                <div class="boxDescription">
                    <p>In de linkse kolom worden de 10 meestvoorkomende labels, uit alle clusters tesamen, getoond die minstens 1 maal werden gebruikt door burgemeesters. In de rechtse kolom wordt hetzelfde gedaan, maar dan voor niet-burgemeesters. Het getal achter ieder label duid aan door hoeveel burgemeesters/niet-burgemeesters het label werd gebruikt.</p>
                </div>
                <div class="boxContent darkBackground">
                    <div class="columnspace twoColumns darkBackground">
                        <div class="column activityChart firstColumn">
                            <h3 class="columnTitle">Burgemeesters</h3>
                            { local:getSingleLabelsBurgemeesters( 10 ) }
                        </div>
                        <div class="column activityChart secondColumn">
                            <h3 class="columnTitle">Niet-Burgemeesters</h3>
                            { local:getSingleLabelsNietBurgemeesters( 10 ) }
                        </div>
                        <br class="clearer"/>
                    </div>
                </div>
            </div>
        </div>
        
        <div class="box" id="onderbrekingsTovEigenBox">
            <div class="margin">
                <h2 class="boxTitle">Aantal onderbrekingen per burgemeester v.s. niet burgemeester</h2>
                                <div class="boxDescription">
                <p>Hier wordt weergegeven hoeveel er gemiddeld onderbroken wordt per burgemeester/niet burgemeester.</p>
                </div>
                <div class="boxContent darkBackground">
                    <div class="columnspace twoColumns darkBackground">
                        <div class="column firstColumn">
                            <h3 class="columnTitle">Burgemeesters</h3>
                            <ul><li>{$onderbrekingsBurg}</li></ul>
                            </div>
                        <div class="column secondColumn">
                            <h3 class="columnTitle">Niet burgemeesters</h3>
                              <ul><li>{$onderbrekingsNBurg}</li></ul>
                        </div>
                    <br class="clearer"/>
                    </div>
                </div> 
           
                <div class="boxContent" style="margin-top:10px">
                        {$onderbrekingsBurgGraf }
                </div>
              </div>
          </div>
                  <div class="box" id="onderbrekingsTovTotaalBox">
            <div class="margin">
                <h2 class="boxTitle">Aantal onderbrekingen t.o.v. eigen functie</h2>
                                <div class="boxDescription">
                <p>Hier wordt weergegeven hoeveel (in percentage) van de burgemeesters/niet burgemeesters ooit onderbroken hebben.</p>
                </div>
                <div class="boxContent darkBackground">
                    <div class="columnspace twoColumns darkBackground">
                        <div class="column firstColumn">
                            <h3 class="columnTitle">Burgemeesters</h3>
                            <ul><li>{$onderbrekingsTovEigenBurg}</li></ul>
                            </div>
                        <div class="column secondColumn">
                            <h3 class="columnTitle">Niet burgemeesters</h3>
                              <ul><li>{$onderbrekingsTovEigennBurg}</li></ul>
                        </div>
                    <br class="clearer"/>
                    </div>
                </div> 
           
                <div class="boxContent" style="margin-top:10px">
                        {$onderbrekingsTovEigenGraf }
                </div>
              </div>
          </div>
</div>
    </body>
</html>
